﻿using System;
using Core.Library;
using DataObject.QA;

namespace Event
{
    public partial class QA : System.Web.UI.Page
    {
        #region variables, constants, properties
        private const int _pageSize = 10;
        private int _pageIndex;
        private bool _isFeature;
        private const string MENU = @"<a class=""{0}"" href=""/hoi-dap.htm"">Câu hỏi thường gặp</a> <a class=""{1} fr"" href=""/cau-hoi-nguoi-dung.htm"">Câu hỏi người chơi</a>";
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            _pageIndex = Utils.GetIdFromRequestString(Utils.PageIndex, SettingValues.PageIndex);
            _isFeature = Utils.GetIdFromRequestString(Utils.IsFeature, true);
            if (!IsPostBack)
            {
                MetaKeyword.AddMetaTag(Page, "Hỏi đáp | " + Const.Meta_Title, Const.Meta_Sapo);
                MetaKeyword.AddFacebookMetaTag(Page, "Hỏi đáp | " + Const.Meta_Title, Const.Meta_Sapo, Const.SITE_URL, Const.Meta_Image);

                ltrMenu.Text = _isFeature
                                   ? string.Format(MENU, "active", string.Empty)
                                   : string.Format(MENU, string.Empty, "active");

                #region QA list

                {
                    var dt = QACache.QA_GetListPaging(
                        isFeature: _isFeature,
                        pageIndex: _pageIndex,
                        pageSize: _pageSize);
                    this.ctrList.Visible = this.ctrList.DataBind(dt);


                    ctrPaging.LinkSite = _isFeature ? "hoi-dap/" : "cau-hoi-nguoi-dung/";
                    ctrPaging.PageSize = _pageSize;
                    var total = QACache.QA_Count(_isFeature);
                    ctrPaging.SumPage = (int)Math.Ceiling((decimal)total / _pageSize);
                    ctrPaging.Visible = ctrPaging.Padding(_pageIndex);
                }
                #endregion
            }
        }
    }
}